package com.ruoyi.caiwu.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.caiwu.domain.AccountingVoucherAttachment;
import com.ruoyi.caiwu.service.IAccountingVoucherAttachmentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 凭证附件Controller
 *
 * @author ruoyi
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/attachment")
public class AccountingVoucherAttachmentController extends BaseController
{
    @Autowired
    private IAccountingVoucherAttachmentService accountingVoucherAttachmentService;

    /**
     * 查询凭证附件列表
     */
    @RequiresPermissions("caiwu:attachment:list")
    @GetMapping("/list")
    public TableDataInfo list(AccountingVoucherAttachment accountingVoucherAttachment)
    {
        startPage();
        List<AccountingVoucherAttachment> list = accountingVoucherAttachmentService.selectAccountingVoucherAttachmentList(accountingVoucherAttachment);
        return getDataTable(list);
    }

    /**
     * 导出凭证附件列表
     */
    @RequiresPermissions("caiwu:attachment:export")
    @Log(title = "凭证附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountingVoucherAttachment accountingVoucherAttachment)
    {
        List<AccountingVoucherAttachment> list = accountingVoucherAttachmentService.selectAccountingVoucherAttachmentList(accountingVoucherAttachment);
        ExcelUtil<AccountingVoucherAttachment> util = new ExcelUtil<AccountingVoucherAttachment>(AccountingVoucherAttachment.class);
        util.exportExcel(response, list, "凭证附件数据");
    }

    /**
     * 获取凭证附件详细信息
     */
    @RequiresPermissions("caiwu:attachment:query")
    @GetMapping(value = "/{attachmentId}")
    public AjaxResult getInfo(@PathVariable("attachmentId") Long attachmentId)
    {
        return success(accountingVoucherAttachmentService.selectAccountingVoucherAttachmentByAttachmentId(attachmentId));
    }

    /**
     * 新增凭证附件
     */
    @RequiresPermissions("caiwu:attachment:add")
    @Log(title = "凭证附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountingVoucherAttachment accountingVoucherAttachment)
    {
        return toAjax(accountingVoucherAttachmentService.insertAccountingVoucherAttachment(accountingVoucherAttachment));
    }

    /**
     * 修改凭证附件
     */
    @RequiresPermissions("caiwu:attachment:edit")
    @Log(title = "凭证附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountingVoucherAttachment accountingVoucherAttachment)
    {
        return toAjax(accountingVoucherAttachmentService.updateAccountingVoucherAttachment(accountingVoucherAttachment));
    }

    /**
     * 删除凭证附件
     */
    @RequiresPermissions("caiwu:attachment:remove")
    @Log(title = "凭证附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attachmentIds}")
    public AjaxResult remove(@PathVariable Long[] attachmentIds)
    {
        return toAjax(accountingVoucherAttachmentService.deleteAccountingVoucherAttachmentByAttachmentIds(attachmentIds));
    }
}
